<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="160px">
      <el-form-item label="请输入插座mac地址:" prop="jobName">
        <el-input v-model="queryParams.mac" placeholder="请输入插座mac地址" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetForm">重置</el-button>
      </el-form-item>
    </el-form>
    <el-row>
      <el-table v-loading="loading" :data="logList">
        <el-table-column type="selection" width="55" align="center" />
        <el-table-column label="设备mac地址" width="200" align="center" prop="deviceId" />
        <el-table-column label="活动类型" width="200" align="center" :formatter="parseType" prop="logType" />
        <el-table-column label="日志备注" width="420" align="center" prop="remakeLog" />
        <el-table-column label="发生时间" width="200" align="center" :formatter="parseTime" prop="logTime" />
        <el-table-column label="持续时间" width="200" align="left" prop="existTime" :formatter="parseMM" />

      </el-table>
      <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
        @pagination="getList" />
    </el-row>
  </div>
</template>
<script>
import Crontab from '@/components/Crontab'
import { parseTime } from "@/utils/ruoyi";
import { listLog } from "@/api/alm/dev-base-info/events-log/events-log";
export default {
  components: {},
  props: [],
  data() {
    return {
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        mac: undefined
      },
      total: 0,
      // 定时任务表格数据
      logList: [],
      // 遮罩层
      loading: false,
      showSearch: true,
      rules: {
        mac: [
          { required: true, message: "插座mac地址不能为空", trigger: "blur" }
        ]
      },
    }
  },
  computed: {},
  watch: {},
  created() { },
  mounted() { },
  methods: {
    resetForm() {
      this.resetForm("queryForm");
    },
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    getList() {
      this.loading = true;
      listLog(this.queryParams).then(response => {
        if (response.code == 200) {
          this.logList = response.rows;
          this.total = response.total;
        } else {

        }
        this.loading = false;
      });
    },
    parseTime(params) {
      return parseTime(params.logTime);
    },
    parseMM(seconds) {
      var time=seconds.existTime/1000;
      // 计算分钟、小时和天数
      const minutes = Math.floor(time / 60);
      const hours = Math.floor(time / (60*60));
      const days = Math.floor(time / (24*60*60));
      // 根据不同的时间范围返回不同的格式
      if (days > 0) {
        return `${days} 天`;
      } else if (hours > 0) {
        return `${hours} 小时`;
      } else if (minutes > 0) {
        return `${minutes} 分钟`;
      } else {
        return `${time} 秒`;
      }
    },
    parseType(params) {
      switch (params.logType) {
        case 1:
          return "登录";
        case 2:
          return "离线";
        case 3:
          return "异常";
        case 4:
          return "重新插拔&登录";
      }
    }
  }
}

</script>
<style></style>
